import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { HomeContainerService } from 'src/app/home/service';
import { ProductList } from '../../domain';

@Component({
  selector: 'app-product-cart',
  templateUrl: './product-cart.component.html',
  styleUrls: ['./product-cart.component.less'],
})
export class ProductCartComponent implements OnInit {
  products!: ProductList[];

  constructor(private data: HomeContainerService) {}
  @Output() cardClick = new EventEmitter();
  ngOnInit() {
    this.getProducts();
  }
  handleClickCard(item: ProductList) {
    this.cardClick.emit(item);
  }
  getProducts() {
    const sub = this.data.getProducts().subscribe(
      (data) => {
        if (data.status === 200) {
          this.products = data.data;
        }
      },
      (error) => {},
      () => {
        sub.unsubscribe();
      }
    );
    this.data.getProducts().subscribe((d) => {
      console.log(d);
    });
  }
}
